#include <iostream>

using std::cout;
using std::endl;

int a;//全局变量，在全局区,默认初始化为0
char *p1;//全局变量，本身在全局区,默认初始化为空
const int kMax = 100;//文字常量区

int main(int argc, char **argv)
{
    const int kMin = 1;//栈区，在栈上的常量
    int b;//局部变量，栈区,默认初始的是随机值
    char *p2;//局部变量，栈区,默认初始的是随机值
    static int c = 10;//静态变量,位于静态区
    int *pInt = new int(10);//pInt本身位于栈上，但是pInt所指的
                            //变量位于堆上
    const char *pstr = "hello,world";//pstr本身位于栈上，pstr
                                     //指向的区域在文字常量区

    printf("\n打印变量的地址\n");
    printf("&a = %p\n", &a);
    printf("&p1 = %p\n", &p1);
    printf("p1 = %p\n", p1);
    printf("&b = %p\n", &b);
    printf("&p2 = %p\n", &p2);
    printf("p2 = %p\n", p2);
    printf("&c = %p\n", &c);
    printf("&pInt = %p\n", &pInt);
    printf("pInt = %p\n", pInt);
    printf("&pstr = %p\n", &pstr);
    printf("pstr = %p\n", pstr);
    printf("&\"hello,world\" = %p\n", &"hello,world");
    printf("&main = %p\n", &main);
    printf("main = %p\n", main);
    printf("&kMax = %p\n", &kMax);
    printf("&kMin = %p\n", &kMin);

    printf("\n打印变量的值\n");
    printf("a = %d\n", a);
    printf("b = %d\n", b);

    delete pInt;
    pInt = nullptr;

    return 0;
}

